package com.yc.vote;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;

import java.util.Collections;

public class CodeGenerator {

    public static void main(String[] args) {
        // 设置代码生成相关参数
        String path = "D:\\_文件柜\\yc127_129\\0711\\vote";
        String url = "jdbc:mysql:///test";
        String username = "root";
        String password = "a";
        String packagePath = "com.yc";
        String moduleName = "vote";
        String author = "LiaoYan";

        System.out.println("------------- 开始生成代码 ---------------");
        String xmlPath = path + "/resources/" + packagePath.replaceAll("\\.","/")
                + "/" + moduleName + "/mapper";
        String javaPath = path + "/java";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(javaPath); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent(packagePath) // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, xmlPath)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.likeTable(new LikeTable("%")); // 生成所有表
                })
                .execute();
        System.out.println("------------- 生成代码完成 ---------------");
    }
}
